﻿using System;
using System.Drawing;

public interface IShape
{
    double Area(); // 计算面积
    bool IsValid(); // 判断形状是否合法
}

public class Circle : IShape
{
    public double Radius { get; set; }
    public const double PI = 3.1415926;

    public Circle(double radius)
    {
        Radius = radius > 0 ? radius : 0;  
    }

    
    public bool IsValid()
    {
        return Radius > 0;
    }

    public double Area()
    {
        if (!IsValid()) return 0;  
        return PI * Radius * Radius;
    }
}

public class Rectangle : IShape
{
    public double Length { get; set; }
    public double Width { get; set; }

    // 构造函数，确保长和宽为正数
    public Rectangle(double length, double width)
    {
        Length = length > 0 ? length : 0;  
        Width = width > 0 ? width : 0;   
    }

    
    public bool IsValid()
    {
        return Length > 0 && Width > 0;
    }

    // 计算面积
    public double Area()
    {
        if (!IsValid()) return 0;  
        return Length * Width;
    }
}

public class Square : IShape
{
    public double Side { get; set; }

    public Square(double side)
    {
        Side = side > 0 ? side : 0;  
    }

    public bool IsValid()
    {
        return Side > 0;
    }

    public double Area()
    {
        if (!IsValid()) return 0;  
        return Side * Side;
    }
}

class Program
{
    static void Main()
    {
        Circle circle1 = new Circle(1);     
        Circle circle2 = new Circle(3);
        Circle circle0 = new Circle(5);
        
        Rectangle rectangle0 = new Rectangle(1, 2);
        Rectangle rectangle1 = new Rectangle(2, 3);
        Rectangle rectangle2 = new Rectangle(5, 3);
        
        Square square0 = new Square(1);  
        Square square1 = new Square(2);
        Square square2 = new Square(1);

        // 输出每个形状的面积和是否合法
        Console.WriteLine($"Circle (Radius = {circle0.Radius}): Area = {circle0.Area()}, Valid = {circle0.IsValid()}");
        Console.WriteLine($"Circle (Radius = {circle1.Radius}): Area = {circle1.Area()}, Valid = {circle1.IsValid()}");
        Console.WriteLine($"Circle (Radius = {circle2.Radius}): Area = {circle2.Area()}, Valid = {circle2.IsValid()}");
       
        Console.WriteLine($"Rectangle (Length = {rectangle0.Length}, Width = {rectangle0.Width}): Area = {rectangle0.Area()}, Valid = {rectangle0.IsValid()}");
        Console.WriteLine($"Rectangle (Length = {rectangle1.Length}, Width = {rectangle1.Width}): Area = {rectangle1.Area()}, Valid = {rectangle1.IsValid()}");
        Console.WriteLine($"Rectangle (Length = {rectangle2.Length}, Width = {rectangle2.Width}): Area = {rectangle2.Area()}, Valid = {rectangle2.IsValid()}");

        Console.WriteLine($"Square (Side = {square0.Side}): Area = {square0.Area()}, Valid = {square0.IsValid()}");
        Console.WriteLine($"Square (Side = {square1.Side}): Area = {square1.Area()}, Valid = {square1.IsValid()}");
        Console.WriteLine($"Square (Side = {square2.Side}): Area = {square2.Area()}, Valid = {square2.IsValid()}");

        // 测试不合法的情况
        Circle invalidCircle = new Circle(-5);  
        Console.WriteLine($"Invalid Circle (Radius = {invalidCircle.Radius}): Area = {invalidCircle.Area()}, Valid = {invalidCircle.IsValid()}");

        double sum = circle0.Area() + circle1.Area() + circle2.Area() + rectangle0.Area() + rectangle1.Area() + rectangle2.Area() + square0.Area() + square1.Area() + square2.Area();
        Console.WriteLine($"Sum = {sum}");
    }
}